package countdownProtocol;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class CountdownServer extends Thread
{

	private int port;
	
	public CountdownServer(int port)
	{
		this.port = port;
	}

	@Override
	public void run()
	{
		try
		{
			ServerSocket socket = new ServerSocket(port);

			Socket toClient = socket.accept();
			InputStream in = toClient.getInputStream();
			OutputStream out = toClient.getOutputStream();

			int fromClient = in.read();
			System.out.println("From Client: "+ fromClient);

			for(int i = fromClient; i > 0; i--)
			{
				out.write(i);
				out.flush();
			}

			toClient.close();


		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
